<?php
if (isset($pro) && !empty($pro)) {
    $cat = $this->mcategories->fetchOne($pro->cid);
    $url = current_url();
    $segment_array = $this->uri->segment_array();
    $s = array_search("size", $segment_array);
    if ($s == '')
        $val1 = 0;
    else
        $val1 = $this->uri->segment($s + 1);
    $b = array_search("bonus", $segment_array);
    if ($b == '')
        $val2 = 0;
    else
        $val2 = $this->uri->segment($b + 1);
    $c = array_search("color", $segment_array);
    if ($c == '')
        $val3 = 0;
    else
        $val3 = $this->uri->segment($c + 1);
    ?>
    <script>
        var CURRENT_URL = '<?PHP echo $url; ?>';
        var valsize = '<?PHP echo $val1; ?>';
        var valbonus = '<?PHP echo $val2; ?>';
        var valcolor = '<?PHP echo $val3; ?>';
        var pattsize;
        var pattbonus;
        var pattcolor;
        function url(val) {
            pattsize = new RegExp("size");
            pattbonus = new RegExp("bonus");
            pattcolor = new RegExp("color");
            if (pattsize.test(val) == true) {
                if (pattsize.test(CURRENT_URL) == true)
                    res = CURRENT_URL.replace("/size/" + valsize, val);
                else
                    res = CURRENT_URL + val;
            }
            if (pattbonus.test(val) == true) {
                if (pattbonus.test(CURRENT_URL) == true)
                    res = CURRENT_URL.replace("/bonus/" + valbonus, val);
                else
                    res = CURRENT_URL + val;
            }
            if (pattcolor.test(val) == true) {
                if (pattcolor.test(CURRENT_URL) == true)
                    res = CURRENT_URL.replace("/color/" + valcolor, val);
                else
                    res = CURRENT_URL + val;
            }
            location.href = res;
        }
    </script>

    <div class="list-content">
        <div class="title-content">
            <div class="title-name">
                <h2>
                    <img src="<?php echo base_url("public/template/frontend/images") ?>/title-pro.png" alt="title">
                    <a href="<?php echo base_url("frontend/home"); ?>">TRANG CHỦ</a> / <a href="<?php echo base_url("frontend/product/pros" . '/' . $cat->id . "/ccat"); ?>"><?php echo $cat->name; ?></a>
                </h2>
                <span>&nbsp;</span>
            </div>                                                      
        </div><!--title-content-->
        <div class="clear-both"></div>
        <div class="main-content">
            <div class="pro-detail">
                <!--detail slide show-->
                <script type="text/javascript" src="<?php echo base_url("public/template/frontend/js/jquery-2.1.1.js") ?>"></script>                                
                <script type="text/javascript" src="<?php echo base_url("public/template/frontend/js/jquery.pikachoose.min.js") ?>"></script>                               
                <script language="javascript">
        $(document).ready(
                function() {
                    $("#pikame").PikaChoose();
                });
                </script>
                <div class="detail-img">
                    <div class="pikachoose">
                        <ul id="pikame" class="jcarousel-skin-pika">
                            <?php
                            if (isset($imgcl) && $imgcl != "") {
                                ?>
                                <li><a href="<?php echo base_url($imgcl->img); ?>" target="_blank"><img src="<?php echo base_url($imgcl->img); ?>" width="121" height="100"/></a></li>
                                <?php
                            } else {
                                ?>
                                <li><a href="<?php echo base_url($pro->img); ?>" target="_blank"><img src="<?php echo base_url($pro->img); ?>" width="121" height="100"/></a></li>
                                <?php
                            }
                            if (isset($img) && !empty($img))
                                foreach ($img as $img) {
                                    ?>
                                    <li><a href="<?php echo base_url($img->img); ?>" target="_blank"><img src="<?php echo base_url($img->img); ?>" width="121" height="100"/></a></li>
                                    <?php
                                }
                            if (isset($imgbn) && $imgbn != "") {
                                ?>
                                <li><a href="<?php echo base_url($imgbn->img); ?>" target="_blank"><img src="<?php echo base_url($imgbn->img); ?>" width="121" height="100"/></a></li>
                                <?php
                            }
                            ?>
                        </ul>
                    </div>
                </div><!--detail-img-->
                <div class="detail-info">
                    <h2><?php echo ucfirst($pro->name); ?></h2>
                    <p>Giá: <span><?php echo number_format($pro->price); ?> đ</span></p>
                    <p>Trạng thái: <?php
                        if ($pro->status == 1)
                            echo "Còn hàng";
                        else
                            echo "Hết hàng";
                        ?></p>
                    <form action="<?php echo base_url("frontend/cart/insert"); ?>" method="post">
                        <input type="hidden" name="data[id]" value="<?php echo $pro->id; ?>">
                        <input type="hidden" name="data[price]" value="<?php echo $pro->price; ?>">
                        <p>
                            <label>Kích cỡ:</label>
                            <select name="size" onchange="return url('/size/' + this.value)">
                                <option value="0"><?php echo $pro->size; ?></option>
                                <?php
                                if (isset($size) && !empty($size))
                                    foreach ($size as $size) {
                                        ?>
                                        <option value="<?php echo $size->id; ?>" <?php if (isset($get['size']) && $get['size'] == $size->id) echo "selected"; ?>>
                                            <?php echo $size->size; ?>
                                        </option>
                                        <?php
                                    }
                                ?>
                            </select>
                            (DxRxC) cm
                        </p>
                        <p>
                            <label>Màu:</label>
                            <select name="color" onchange="return url('/color/' + this.value);">
                                <option value="0">Mặc định</option>
                                <?php
                                if (isset($color) && !empty($color))
                                    foreach ($color as $color) {
                                        ?>
                                        <option value="<?php echo $color->id; ?>" <?php if (isset($get['color']) && $get['color'] == $color->id) echo "selected"; ?>>
                                            <?php echo $color->color; ?>
                                        </option>
                                        <?php
                                    }
                                ?>
                            </select>
                        </p>
                        <p>
                            <label>Phụ kiện:</label>
                            <select name="bonus" onchange="return url('/bonus/' + this.value);">
                                <option value="0">Không</option>
                                <?php
                                if (isset($bonus) && !empty($bonus))
                                    foreach ($bonus as $bonus) {
                                        ?>
                                        <option value="<?php echo $bonus->id; ?>" <?php if (isset($get['bonus']) && $get['bonus'] == $bonus->id) echo "selected"; ?>>
                                            <?php echo $bonus->bonus; ?>
                                        </option>
                                        <?php
                                    }
                                ?>
                            </select>
                        </p>
                        <p><label>Số lượng:</label>
                            <input type="text" value="1" name="data[qty]">
                        </p>
                        <p>                                           
                            <input type="submit" name="btnAdd" value="Đặt hàng">
                        </p>
                    </form>
                </div>
                <div class="clear-both"></div>
                <div class="detail-des">                                    
                    <script src="<?php echo base_url("public/template/frontend/js/jquery-ui.js") ?>"></script>
                    <script>
                                $(function() {
                                    $("#tabs").tabs();
                                });
                    </script>
                    <div id="tabs">
                        <ul>
                            <li><a href="#tabs-1">Mô tả sản phẩm</a></li>
                            <li><a href="#tabs-2">Bình luận</a></li>                    
                        </ul>
                        <div id="tabs-1">
                            <p><?php echo $pro->des; ?></p>
                        </div>
                        <div id="tabs-2">                                         
                            <div id="fb-root">
                                <div class="fb-comments" data-href="<?php echo base_url("frontend/product/detail") . "/" . $pro->id; ?>" data-numposts="5" data-width="600"></div>
                            </div>
                            <script>(function(d, s, id) {
                                    var js, fjs = d.getElementsByTagName(s)[0];
                                    if (d.getElementById(id))
                                        return;
                                    js = d.createElement(s);
                                    js.id = id;
                                    js.src = "//connect.facebook.net/vi_VN/all.js#xfbml=1";
                                    fjs.parentNode.insertBefore(js, fjs);
                                }(document, 'script', 'facebook-jssdk'));
                            </script>                                      
                        </div>                 
                    </div><!--tabs-->
                </div><!--detail-des-->
            </div><!--pro-detail-->
        </div><!--main-content-->                       
    </div><!--list-content-->
    <?php
    if (isset($prorelate) && !empty($prorelate)) {
        ?>
        <div class="list-content">
            <div class="title-content">
                <div class="title-name">
                    <h2>
                        <img src="<?php echo base_url("public/template/frontend/images") ?>/title-pro.png" alt="title">
                        SẢN PHẨM LIÊN QUAN
                    </h2>
                    <span>&nbsp;</span>
                </div>                        
            </div><!--title-content-->
            <div class="clear-both"></div>
            <div class="main-content">
                <?php
                foreach ($prorelate as $p) {
                    ?>
                    <div class="pro_item">
                        <div class="item_img">
                            <a href="<?php echo base_url("frontend/product/detail") . '/' . $p->id; ?>"><img src="<?php echo base_url($p->img); ?>" alt=""></a>
                        </div>
                        <div class="item_name">
                            <a href="<?php echo base_url("frontend/product/detail") . '/' . $p->id; ?>" title="<?php echo $p->img ?>"><?php echo ucfirst(word_limiter($p->name, 6)); ?></a>
                        </div>
                        <div class="item_price">
                            <span><?php echo number_format($p->price); ?> đ</span>
                        </div>
                    </div>
                    <?php
                }
                ?>                    
            </div><!--main-content-->
        </div><!--list-content-->
        <?php
    }
} else {
    ?>
    <h2 style="float: left; margin: 15px 0 0 15px;">Không có dữ liệu</h2>
<?php } ?>
